import axios from "./http.js";
import _ from "lodash";

/*
 * 部门管理
 */
// 获取公司列表
export function getCorporationList(config) {
  let url = "/bs/corporation/list";
  const opts = _.merge({}, config || {});

  return axios.get(url, opts);
}

// 添加或编辑公司
export function addCorporation(data, config) {
  let url = "/bs/corporation/save";

  data = data || {};
  config = config || {};
  return axios.post(url, data, config);
}
// 获取公司详情
export function getCorporationDetail(config) {
  let url = "/bs/corporation";
  const opts = _.merge({}, config || {});
  url = url + "/" + opts.params.id;
  delete opts.params.id;

  return axios.get(url, opts);
}
// 删除公司
export function deleteCorporation(data, config) {
  let url = "/bs/corporation/delete";

  data = data || {};
  config = config || {};
  url = url + "/" + data.id;
  delete data.id;
  return axios.post(url, data, config);
}

// 获取部门列表
export function getDepartmentList(config) {
  let url = "/bs/department/list";
  const opts = _.merge({}, config || {});

  return axios.get(url, opts);
}

// 添加或编辑部门
export function addDepartment(data, config) {
  let url = "/bs/department/save";

  data = data || {};
  config = config || {};
  return axios.post(url, data, config);
}
// 获取部门详情
export function getDepartmentDetail(config) {
  let url = "/bs/department";
  const opts = _.merge({}, config || {});
  url = url + "/" + opts.params.id;
  delete opts.params.id;

  return axios.get(url, opts);
}
// 删除部门
export function deleteDepartment(data, config) {
  let url = "/bs/department/delete";

  data = data || {};
  config = config || {};
  url = url + "/" + data.id;
  delete data.id;
  return axios.post(url, data, config);
}

/**
 * 平台管理
 */
// 获取平台列表
export function getPlatformList(config) {
  let url = "/bs/platform/list";

  const opts = _.merge({ headers: { isLogin: false } }, config || {});
  return axios.get(url, opts);
}

// 添加或编辑平台
export function addPlatform(data, config) {
  let url = "/bs/platform/save";

  data = data || {};
  config = config || {};
  return axios.post(url, data, config);
}
// 获取平台详情
export function getPlatformDetail(config) {
  let url = "/bs/platform";
  const opts = _.merge({}, config || {});
  url = url + "/" + opts.params.id;
  delete opts.params.id;

  return axios.get(url, opts);
}
// 删除平台
export function deletePlatform(data, config) {
  let url = "/bs/platform/delete";

  data = data || {};
  config = config || {};
  url = url + "/" + data.id;
  delete data.id;
  return axios.post(url, data, config);
}

/**
 * 功能管理
 */
// 获取功能列表
export function getFunctionList(config) {
  let url = "/bs/function/list";

  const opts = _.merge(config || {});
  return axios.get(url, opts);
}

// 添加或编辑功能
export function addFunction(data, config) {
  let url = "/bs/function/save";

  data = data || {};
  config = config || {};
  return axios.post(url, data, config);
}
// 获取功能详情
export function getFunctionDetail(config) {
  let url = "/bs/function";
  const opts = _.merge({}, config || {});
  url = url + "/" + opts.params.id;
  delete opts.params.id;

  return axios.get(url, opts);
}
// 删除功能
export function deleteFunction(data, config) {
  let url = "/bs/function/delete";

  data = data || {};
  config = config || {};
  url = url + "/" + data.id;
  delete data.id;
  return axios.post(url, data, config);
}

/**
 * 角色管理
 */
// 获取角色列表
export function getRoleList(config) {
  let url = "/bs/role/list";

  const opts = _.merge(config || {});
  return axios.get(url, opts);
}

// 添加或编辑角色
export function addRole(data, config) {
  let url = "/bs/role/save";

  data = data || {};
  config = config || {};
  return axios.post(url, data, config);
}
// 获取角色详情
export function getRoleDetail(config) {
  let url = "/bs/role";
  const opts = _.merge({}, config || {});
  url = url + "/" + opts.params.id;
  delete opts.params.id;

  return axios.get(url, opts);
}
// 删除角色
export function deleteRole(data, config) {
  let url = "/bs/role/delete";

  data = data || {};
  config = config || {};
  url = url + "/" + data.id;
  delete data.id;
  return axios.post(url, data, config);
}

// 增加角色的功能
export function addRoleFunction(data, config) {
  let url = "/bs/role/saveFunc";

  data = data || {};
  config = config || {};
  return axios.post(url, data, config);
}
// 获取角色详情
export function getRoleFunction(config) {
  let url = "/bs/role/func";
  const opts = _.merge({}, config || {});
  url = url + "/" + opts.params.id;
  delete opts.params.id;

  return axios.get(url, opts);
}

/**
 * 用户管理
 */
// 获取用户列表
export function getUserList(config) {
  let url = "/bs/user/list";

  const opts = _.merge(config || {});
  return axios.get(url, opts);
}

// 添加或编辑用户
export function addUser(data, config) {
  let url = "/bs/user/save";

  data = data || {};
  config = config || {};
  return axios.post(url, data, config);
}
// 获取用户详情
export function getUserDetail(config) {
  let url = "/bs/user/getById";
  const opts = _.merge({}, config || {});
  url = url + "/" + opts.params.id;
  delete opts.params.id;

  return axios.get(url, opts);
}
// 删除用户
export function deleteUser(data, config) {
  let url = "/bs/user/delete";

  data = data || {};
  config = config || {};
  url = url + "/" + data.id;
  delete data.id;
  return axios.post(url, data, config);
}
// 更改用户状态
export function updateUserStatus(data, config) {
  let url = "/bs/user/modifyStatus";

  data = data || {};
  config = config || {};
  return axios.post(url, data, config);
}
